<?php





    $id = !empty($_GET['id'])?$_GET['id']:'';
    //echo $id;die;
    //print_r($_SERVER);die;

    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

        $id = $_POST['id'];
        $filed = $_POST['filed'];
        $val = $_POST['val'];

        $sql = "update `news` set `$filed` = '$val' where `id`=$id";
        mysqli_query($link,$sql);
        $_rows = mysqli_affected_rows($link);
        echo $_rows;
        die;
    };

    $sql = "select * from `news` where `id` =$id";

    $result = mysqli_query($link,$sql);
    $data = mysqli_fetch_assoc($result);

    $title = $data['title'];
    $type = $data['type'];
    $author = $data['author'];
    $content = $data['content'];
    //print_r($data);die;


    if (!empty($_POST)) {

        $upda['title'] = $_POST['title'];
        $upda['type'] = $_POST['type'];
        $upda['author'] = $_POST['author'];
        $upda['content'] = $_POST['content'];

        // $sql = "update `news` set `title`='$title',`type`='$type',`author`='$author',`content`='$content' where `id`=$id";


        // mysqli_query($link,$sql);
        $rows = getUpdate('id',$id,$upda);
        if ($rows >= 0) {
            echo '<script type="text/javascript">alert("编辑成功！");self.location.href="index.php?c=news&a=list&admin=1";</script>';die;
        }else{
            echo '<script type="text/javascript">alert("编辑失败！");history.go(-1);</script>';die;
        };
    };





?>